package Vista;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controlador.Sistema;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaUsuarios extends PantallaUsuario {
	
	private static final long serialVersionUID = 1L;
	
	public AltaUsuarios(Sistema s){
		
		super(s, "Alta Usuarios");
		this.inicializarPantalla();
	}
	
	public void inicializarPantalla(){
		this.initGUI();
		try{
		{
			this.desBloquearTodos();
			btnOK.setText("Crear");
			btnOK.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {
					// TODO Auto-generated method stub
					if (controlCampos()){
					try {
						
						sistema.altaUsuario(txtNombre.getText(), txtApellido.getText(), txtDNI.getText(), txtDomicilio.getText(), txtTelefono.getText(), txtEmail.getText());
						limpiarCampos();
						
					} catch (Exception ex) {
						// TODO: handle exception
						ex.printStackTrace();
						JFrame j1 = new JFrame();
						if (ex.getMessage().equals("ExisteUsuario")){						
							JOptionPane.showMessageDialog(j1,
									"Ya existe un usuario con ese DNI","Usuario Existente",JOptionPane.WARNING_MESSAGE);
							return;
						}
						else
						{													
							JOptionPane.showMessageDialog(j1,
									"Se produjo un error inesperado. Verifique los datos cargados!","Error Encontrado",JOptionPane.ERROR_MESSAGE);
						}	
					}
					}

				}
			});
		}
			
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		
	}
	
	
}
